Activities
A workflow is a
sequence of activities executed by the workflow engine. An activity
should be modeled as a real-world action required for completing a
parent business process. An activity is a class that encapsulates logic
and can potentially be reused across different workflows.
WF includes several
activities known as the base activity library. Activities from the base
activity library are commonly used with sequential workflows (Table 2).
Table 2. Base library activities commonly used with sequential workflows.
Activity | Description | |
---|
IfElse | allows
conditions to be specified in the workflow and the runtime engine
evaluates each condition and acts upon it based on the result (the IfElse activity can contain other IfElse activities and a default IfElse activity if no other condition is met) | Looping and Synchronization |
While | accepts
a condition and evaluates it at the beginning of every iteration (if
the condition is true, the child activity is run repeatedly until the
condition becomes false) |
Replicator | executes a child activity a given number of times (similar to the foreach statement in C#) |
Sequence | is used to execute a group of activities, one at a time, in a predefined order |
Parallel | executes
two or more sequences of activities in parallel or in an interleaved
manner (all sequence activities must be completed before the workflow
moves to the next activity) |
Listen | is used to idle the workflow process and wait for a wake-up call (the Listen
activity is typically used when human interaction is required—it
serializes the workflow and goes into a passive mode when it is waiting
for human intervention and upon receiving an event, it reactivates the
workflow and continues with the processing logic) | Human Intervention |
EventDriven | is implemented by using the EventDriven activity (a ListenEventDriven activities and child activities that represent human events) activity must contain |
HandleExternalEvent | is invoked when an event specified in an interface is raised (the HandleExternalEvent activity is used by WF to communicate with an external service) |
Delay | is used to suspend the execution of the workflow for a specified amount of time |
Code | allows source code to be injected directly into the workflow (it fires the ExecuteCode event that executes the code, plus this activity can call an external assembly) | Execution |
CallExternalMethod | is
used to call a method in a class available to the workflow (the
interface and its implementation must be available in the same assembly) |
InvokeWorkflow | invokes another workflow to start executing |
InvokeWebService | invokes
a Web service external to the workflow application (creates a Web
reference to a Web service and allows operations on the service to be
invoked) |
WebServiceInput | enables a workflow to receive a Web service request |
WebServiceOutput | pairs with a WebServiceInput activity to respond to a service request (to use this activity, the WebServiceInput activity must be configured first) |
TransactionScope | is used to represent System.Transactions in WF (supports all the properties currently supported by System.Transactions) |
Terminate | is used to terminate the execution of the workflow |
State
machine workflows provide a way of defining workflows that match an
organization’s business process by using states, events, and transitions
to model workflow logic. A state represents a snapshot of the business
process. The workflow is always in one state and will transition to a
new state when it receives an event. Typically, some action will take
place in the outside world for the state in the workflow to be
transitioned to a new state. On reaching the final state, the workflow
is completed.
The base activity library includes several activities designed to enable state machine workflows (Table 3).
Table 3. Base library activities commonly used with state machine workflows.
Activity | Description |
---|
State | represents
a state in a state machine workflow (when an event arrives, the
workflow will transition from one state activity to a new state
activity) |
EventDriven | represents an event handler in a state machine and is placed inside a state activity |
SetState | is used to model transitions in a state machine workflow (includes the TargetStateName property that points to the destination state) |
StateInitializationStateFinalization
| used
to perform pre- and post-processing in a state and run when the state
machine transitions into the state containing the initialization
activity (the StateFinalization activity runs when the state machine transitions out of a state) |
A state machine workflow is
commonly consumed by one or more UI components that must reflect the
current state of the workflow and allow users to only perform legal
events. WF includes the StateMachineWorkflowInstance
class that provides an API to manage and query a state machine
workflow. The class includes properties used to fetch the current state
name and find legal transitions for the state. It also includes
properties that provide a history of all the states the workflow has
been through.